home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14642
/
14642.xpi
/
chrome
/
content
/
historyResults.js
< prev
next >
Wrap
Text File
|
2009-10-07
|
17KB
|
473 lines
/* Copyright 2009, Boomtango.com. All Rights Reserved. */
/* historyResults.js
* Responsible for results view
*/
bthistory.controllers["results"] = {
handleUpArrow: function(){
var sels = document.getElementsByClassName("selected");
var box = document.getElementById("resultsdata");
if(!box){
return;
}
var body = document.getElementById("body");
if(sels.length == 0){
if(box.childNodes.length == 0){
return;
} else {
bthistory.selectNode(box.lastChild);
bthistory.scrollIntoView(body, box.lastChild);
}
} else {
var sel = sels[0];
if(sel.previousSibling){
bthistory.selectNode(sel.previousSibling);
bthistory.scrollIntoView(body, sel.previousSibling);
} else {
var nextarrow = document.getElementById("searchprev");
if(nextarrow){
nextarrow.click();
}
}
}
},
handleDownArrow: function(){
var sels = document.getElementsByClassName("selected");
var box = document.getElementById("resultsdata");
if(!box){
return;
}
var body = document.getElementById("body");
if(sels.length == 0){
if(box.childNodes.length == 0){
return;
} else {
bthistory.selectNode(box.firstChild);
bthistory.scrollIntoView(body, box.firstChild);
}
} else {
var sel = sels[0];
if(sel.nextSibling){
bthistory.selectNode(sel.nextSibling);
bthistory.scrollIntoView(body, sel.nextSibling);
} else {
var nextarrow = document.getElementById("searchnext");
if(nextarrow){
nextarrow.click();
}
}
}
},
onHistoryAdd: function(data) {
},
onHistoryChange: function(data) {
},
handleResize: function(){
var winx = document.getElementById("boomtangoHistory");
var win = {
h: winx.boxObject.height,
w: winx.boxObject.width,
x: 0,
y: 0
};
var panel = document.getElementById("rightpanel");
var panelbox = {
h: panel.boxObject.height,
w: panel.boxObject.width,
x: panel.boxObject.x,
y: panel.boxObject.y
};
var w = win.w - panelbox.w - 160;
var classes = [ 'resultstime', 'results_title', 'results_url', 'resultheader'];
var widths = [ w, w, w, w + 60];
var clen = classes.length;
for(var y = 0; y < clen; y++){
var a = document.getElementsByClassName(classes[y]);
var len = a.length;
var w = widths[y];
for(var x = 0; x < len; x++){
a[x].setAttribute('style', 'width: ' + w + "px;");
}
}
},
queryTracker: function(){
var starttime = -1;
var endtime = -1;
if(document.getElementById("searchfromcb").checked){
var d = document.getElementById("searchfrom").dateValue;
var d2 = new Date(
d.getFullYear(),
d.getMonth(),
d.getDate(),
0,
0
);
starttime = d2.getTime();
}
if(document.getElementById("searchtocb").checked){
var d = document.getElementById("searchto").dateValue;
var d2 = new Date(
d.getFullYear(),
d.getMonth(),
d.getDate(),
23,
59,
59
);
endtime = d2.getTime();
}
switch(bthistory.currResultType){
case 'visits':
return bthistory.storage.queryTrackerByID(
bthistory.currVisitID,
bthistory.currOrder,
bthistory.currOffset,
bthistory.app.searchItemsPerPage,
true,
bthistory.currOrderDesc,
bthistory.currTypes,
starttime,
endtime
);
case 'more':
return bthistory.storage.queryTrackerByMoreItems(
bthistory.currMoreType,
bthistory._range.start,
bthistory._range.end,
bthistory.currOrder,
bthistory.currOffset,
bthistory.app.searchItemsPerPage,
true,
bthistory.currOrderDesc
);
case 'search':
default:
return bthistory.storage.queryTrackerBySearch(
bthistory.currQuery,
bthistory.currOrder,
bthistory.currOffset,
bthistory.app.searchItemsPerPage,
true,
bthistory.currOrderDesc,
bthistory.currTypes,
starttime,
endtime
);
}
},
loadView: function(){
document.loadOverlay("chrome://boomtango/content/historyResults.xul", this);
},
observe: function(subject, topic, data) {
if(topic == "xul-overlay-merged"){
bthistory.app.log("historyResults::overlayLoaded");
this.loadMergedView();
}
},
/*
loadMergedView is handled after view has been merged.
*/
loadMergedView: function() {
bthistory.app.log("historyResults::loadMergedView");
var data = bthistory._data.data;
this.total = bthistory._data.totalcount;
if(this.total){
this.loadHeader(data);
this.loadData(data);
this.loadPagination();
} else {
var body = document.getElementById("body");
var label= document.createElement("label");
label.setAttribute("value", bthistory.app.getString("history.nodatafound"));
label.className = "nodatafound";
body.appendChild(label);
document.getElementById("resultcontainer").setAttribute("hidden", "true");
}
document.getElementById("duration_control").setAttribute("hidden", "true");
document.getElementById("gotoday").setAttribute("hidden", "true");
document.getElementById("gotodate").setAttribute("hidden", "true");
document.getElementById("filter_box").setAttribute("hidden", "true");
document.getElementById("searchdate_box").setAttribute("hidden", "false");
bthistory.resizeToWindow(true);
},
gotoPage: function(start){
bthistory.currOffset = start;
bthistory.resetHash();
bthistory.updateView();
},
loadPageClick: function(label, start){
var self = this;
label.addEventListener(
"click",
function(){
self.gotoPage(start);
},
false
);
},
loadPagination: function(){
var container = document.getElementById('resultcontainer');
var hbox = document.createElement("hbox");
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
hbox.appendChild(spacer);
const ITEMSPERPAGE = bthistory.app.searchItemsPerPage;
if(bthistory.currOffset){
var vbox = document.createElement("vbox");
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
vbox.appendChild(spacer);
var label= document.createElement("image");
label.id = "searchprev";
label.className = "resultsarrow";
label.setAttribute('src', 'chrome://boomtango/skin/arrow_left.png');
var start = bthistory.currOffset - ITEMSPERPAGE;
if(start < 0) {
start = 0;
}
this.loadPageClick(label, start);
vbox.appendChild(label);
hbox.appendChild(vbox);
}
var startIndex = Math.floor(bthistory.currOffset / (ITEMSPERPAGE * 10)) * 10;
var currIndex = Math.floor(bthistory.currOffset / ITEMSPERPAGE);
var endIndex = startIndex + 10;
if(this.total < endIndex * ITEMSPERPAGE){
endIndex = Math.floor(this.total / ITEMSPERPAGE) + ((this.total % ITEMSPERPAGE) > 0 ? 1 : 0);
}
for(var x = startIndex; x < endIndex; x++){
if(x != currIndex){
var label= document.createElement("label");
var start = x * ITEMSPERPAGE;
this.loadPageClick(label, start);
label.className = "resultspagelink";
label.setAttribute("value", (x + 1).toString());
hbox.appendChild(label);
} else {
var label= document.createElement("label");
var start = x * ITEMSPERPAGE;
label.className = "resultscurrpage";
label.setAttribute("value", (x + 1).toString());
hbox.appendChild(label);
}
}
if(bthistory.currOffset + ITEMSPERPAGE < this.total){
var vbox = document.createElement("vbox");
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
vbox.appendChild(spacer);
var label= document.createElement("image");
label.className = "resultsarrow";
label.setAttribute('src', 'chrome://boomtango/skin/arrow_right.png');
label.id = "searchnext";
var start = bthistory.currOffset + ITEMSPERPAGE;
this.loadPageClick(label, start);
vbox.appendChild(label);
hbox.appendChild(vbox);
}
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1");
hbox.appendChild(spacer);
container.appendChild(hbox);
},
loadHeader: function(data){
var label = document.getElementById("resultcount");
label.setAttribute("value",
bthistory.app.getString(
"results.count",
(bthistory.currOffset + 1).toString(),
(bthistory.currOffset + data.length).toString(),
this.total.toString()
)
);
var menu = document.getElementById("sortby");
if(bthistory.currOrder != "starttime" || !bthistory.currOrderDesc){
if(bthistory.currOrderDesc){
if(bthistory.currOrder == "title"){
menu.selectedIndex = 3;
} else if(bthistory.currOrder == "timespent"){
menu.selectedIndex = 4;
}
} else {
if(bthistory.currOrder == "starttime"){
menu.selectedIndex = 1;
} else if(bthistory.currOrder == "title"){
menu.selectedIndex = 2;
}
}
}
var self = this;
menu.addEventListener(
"select",
function(){
self.handleSort();
},
false
);
document.getElementById("body_header").
setAttribute("hidden", "false");
},
handleSort: function(){
bthistory.app.log("results::handleSort");
var menu = document.getElementById("sortby");
switch(menu.selectedIndex){
case 0:
bthistory.currOrder = "starttime";
bthistory.currOrderDesc = true;
break;
case 1:
bthistory.currOrder = "starttime";
bthistory.currOrderDesc = false;
break;
case 2:
bthistory.currOrder = "title";
bthistory.currOrderDesc = false;
break;
case 3:
bthistory.currOrder = "title";
bthistory.currOrderDesc = true;
break;
case 4:
bthistory.currOrder = "timespent";
bthistory.currOrderDesc = true;
break;
}
bthistory.resetHash();
bthistory.updateView();
},
addStartClickHandler: function(linkNode, item){
linkNode.addEventListener(
"click",
function(){
bthistory.currTime = item.starttime;
bthistory.loadView('calendar', 'hour', item.ftsrowid);
},
false
);
},
loadData: function(data){
var len = data.length;
var fi = Components.classes["@mozilla.org/browser/favicon-service;1"].getService(Components.interfaces.nsIFaviconService);
var io = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService2);
var container = document.getElementById('resultsdata');
var ismoreitems = bthistory.currResultType == 'more';
for(var x = 0; x < len; x++){
var item = data[x];
var row = document.createElement('vbox');
row.className = "resultsbox";
row.setAttribute("contentID", item.ftsrowid);
if(ismoreitems){
row.setAttribute("trackerID", item.id);
}
var hcontainer = document.createElement('hbox');
var thumbnail = document.createElement('image');
thumbnail.className = "resultsthumb";
var thumbrec = boomtangoApp.getThumbID(item.url);
thumbnail.setAttribute("src",
bthistory.app.getThumb(thumbrec.id));
hcontainer.appendChild(thumbnail);
var vcontainer = document.createElement('vbox');
// icon and title
var hbox = document.createElement('hbox');
hbox.setAttribute("flex", "1");
hbox.setAttribute("style", "background-color: transparent;");
var title = item.title || item.url;
var vbox = document.createElement('vbox');
vbox.setAttribute("style", "background-color: transparent;");
var linkNode = document.createElement("label");
linkNode.className = "results_title";
linkNode.setAttribute("value", title);
linkNode.setAttribute("crop", "end");
linkNode.setAttribute("flex", "1");
hbox.appendChild(vbox);
hbox.appendChild(linkNode);
vcontainer.appendChild(hbox);
//url
var hbox = document.createElement("hbox");
var linkNode = document.createElement("label");
linkNode.className = "text-link results_url";
linkNode.setAttribute("href", item.url);
linkNode.setAttribute("style",
"background-color: transparent;color:blue;");
linkNode.setAttribute("value", item.url);
linkNode.setAttribute("crop", "end");
linkNode.setAttribute("flex", "1");
hbox.appendChild(linkNode);
var spacer = document.createElement("spacer");
spacer.setAttribute('flex', "1000");
hbox.appendChild(spacer);
vcontainer.appendChild(hbox);
//starttime
var hbox = document.createElement("hbox");
hbox.className = "resultstime";
var label =document.createElement("label");
label.className = "resultslabel";
label.setAttribute('value',
bthistory.app.getString("results.visited"));
hbox.appendChild(label);
var linkNode = document.createElement("label");
linkNode.className = "resultsstart";
linkNode.setAttribute("value", bthistory.datestring(item.starttime));
this.addStartClickHandler(linkNode, item);
linkNode.setAttribute("crop", "end");
linkNode.setAttribute("flex", "1");
hbox.appendChild(linkNode);
//timespent
var label =document.createElement("label");
label.className = "resultslabel";
label.setAttribute('value',
bthistory.app.getString("results.timespent"));
hbox.appendChild(label);
var linkNode = document.createElement("label");
linkNode.setAttribute("value", bthistory.duration(item.endtime - item.starttime));
linkNode.setAttribute("crop", "end");
linkNode.setAttribute("flex", "1");
hbox.appendChild(linkNode);
var spacer = document.createElement("spacer");
spacer.setAttribute('flex', "1000");
hbox.appendChild(spacer);
vcontainer.appendChild(hbox);
hcontainer.appendChild(vcontainer);
row.appendChild(hcontainer);
container.appendChild(row);
}
/*
if(len < bthistory.app.searchItemsPerPage){
var spacer = document.createElement('spacer');
spacer.setAttribute("flex", "1000");
container.appendChild(spacer);
}
*/
}
};